package com.ccl.iot.views;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;

import com.ccl.iot.R;
import com.ccl.iot.device.DeviceIconProvider;
import com.ccl.iot.device.IOTSecurityArm;

/**
 * 创建者     dong
 * 创建时间   2017/5/9
 * 描述	     安防主机单个防区view
 */

public class SingleSecurityArmView extends RelativeLayout {
    public static int STATE_NORMAL = 0;
    public static int STATE_DELETE = 1;

    private ImageView mSecurityImg;
    private MarqueeLabel mMqlName;
    private int mIndex;

    public SingleSecurityArmView(Context context) {
        this(context, null);
    }

    public SingleSecurityArmView(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public SingleSecurityArmView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        init();
    }

    private void init() {
        View.inflate(getContext(), R.layout.view_single_security, this);
        mSecurityImg = (ImageView) findViewById(R.id.iv_security);
        mMqlName = (MarqueeLabel) findViewById(R.id.mql_security_name);
    }

    public ImageView getSecurityImg() {
        return mSecurityImg;
    }

    public void initData(IOTSecurityArm dev, int index) {
        if (dev != null) {
            mIndex = index;
            mMqlName.setText(dev.getName(index));

            mSecurityImg.setImageResource(DeviceIconProvider.getProbeSelectorId(dev.getIcon(index)));
            mSecurityImg.setTag(index);
        }
    }

    public int getIndex() {
        return mIndex;
    }

    public void setOnClickListener(OnClickListener l, OnLongClickListener ll) {
        if (l != null) {
            mSecurityImg.setOnClickListener(l);
        }

        if(ll != null){
            mSecurityImg.setOnLongClickListener(ll);
        }
    }



}
